package restful_apis.knowledge_graph;

import com.fasterxml.jackson.databind.node.ObjectNode;
import common.helper.json.JavaToJsonString;
import knowlwdge_graph.knowledge_etl.concept_etl.ConceptExtractor;
import knowlwdge_graph.knowledge_etl.entity_etl.EntityExtractor;
import knowlwdge_graph.knowledge_etl.relation_etl.RelationExtractor;
import org.springframework.stereotype.Component;
import query_understanding.query_understand.tree_progress.DocumentQueryProgress;
import restful_apis.common.MediaTypes;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.xml.ws.Response;

/**
 * Created by julianzliu on 5/4/2017.
 */


@Path("/knowledge")
@Produces(MediaTypes.JSON_UTF8)
@Component
public class KnowledgeGraphRest {


    private EntityExtractor extractor;
    private RelationExtractor relationExtractor;
    private ConceptExtractor conceptExtractor;


    public KnowledgeGraphRest(){

        this.extractor = new EntityExtractor();

        this.relationExtractor = new RelationExtractor();

        this.conceptExtractor = new ConceptExtractor();

    }

    @GET
    @Path("/_entity")
    @Produces(MediaTypes.JSON_UTF8)
    public String  importEntity(
            @QueryParam("entity") String enitty
    ){
        this.extractor.importEntityFromPostgreToOrient( enitty );

        return "{\"result\" : \"ok\" }";
    }


    @GET
    @Path("/_relation")
    @Produces(MediaTypes.JSON_UTF8)
    public String  importRelation(
            @QueryParam("relation") String relation,
            @QueryParam("gloss") String gloss
    ){
        this.relationExtractor.insertRelationGloss(relation, gloss);

        return "{\"result\" : \"ok\" }";
    }


    @GET
    @Path("/_concept")
    @Produces(MediaTypes.JSON_UTF8)
    public String  importConcept(
            @QueryParam("concept") String concept,
            @QueryParam("gloss") String gloss
    ){

        this.conceptExtractor.insertConceptGloss( concept, gloss);
        // <wordnet_president_110467179>

        return "{\"result\" : \"ok\" }";
    }


}
